﻿using System;
using System.Web.Mvc;
using System.Web;

namespace JinianNet.JNCms.Filters
{
    public class BasePageFilter : FilterAttribute,IAuthorizationFilter,IActionFilter,IResultFilter, IExceptionFilter
    {

        #region IAuthorizationFilter 成员

        public virtual void OnAuthorization(AuthorizationContext filterContext)
        {
            //throw new NotImplementedException();
        }

        #endregion


        #region IActionFilter 成员

        public virtual void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //throw new NotImplementedException();
        }

        public virtual void OnActionExecuting(ActionExecutingContext filterContext)
        {

            //filterContext.Result = new
            //throw new NotImplementedException();
        }

        #endregion

        #region IResultFilter 成员

        public virtual void OnResultExecuted(ResultExecutedContext filterContext)
        {
            //throw new NotImplementedException();
        }

        public virtual void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (Config.Site.IsClose)
            {
                filterContext.Result = new ContentResult() { Content = Config.Site.CloseReason };
            }
            //throw new NotImplementedException();
        }

        #endregion

        #region IExceptionFilter 成员

        public virtual void OnException(ExceptionContext filterContext)
        {
            if (!filterContext.ExceptionHandled)
            {
                //Tips(filterContext.HttpContext.Response, filterContext.Exception.Message, null, false, filterContext.Exception.ToString());
                filterContext.Result = new ContentResult() { Content = Config.GetTips( filterContext.Exception.Message,null,false) };
                filterContext.ExceptionHandled = true;
            }
        }

        #endregion
    }
}
